package com.good.jzhouse.dao;

import com.good.jzhouse.bean.Menu;
import org.apache.ibatis.annotations.Many;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;

import java.util.List;

public interface MenuDao {


    /* 查询Menu */
    @Select("select * from Menu")
    List<Menu> findAll();

    /* 根据id查询菜单编号 */
    @Select("select * from Menu where mid=#{id}")
    @Results({
            @Result(id=true,column="mid",property="mid"),
            @Result(column="mname",property="mname"),
            @Result(column="pid",property="pid"),
            @Result(column="location",property="location"),
            @Result(column="mid",property="list",many=@Many(select="com.good.jzhouse.dao.MenuDao.findByPid"))
    })
    Menu selectById(Integer id);

    @Select("SELECT * " +
            "FROM menu " +
            "WHERE pid = #{pid}")
    List<Menu> findByPid(Integer pid);

    @Select("SELECT * \n" +
            " FROM `menu` m , `root` r\n" +
            " WHERE r.`mid` = m.`mid`\n" +
            " AND m.`pid` = 0 \n" +
            " AND r.`roleId` = #{roleId}\n" +
            " ORDER BY m.`mid`;")
    @Results({
            @Result(id=true,column="mid",property="mid"),
            @Result(column="mname",property="mname"),
            @Result(column="pid",property="pid"),
            @Result(column="location",property="location"),
            @Result(column="mid",property="list",many=@Many(select="com.good.jzhouse.dao.MenuDao.findByPid"))
    })
    List<Menu> SelectMenu(Integer roleId);
}
